<template>
  <view class="container">
    <!-- Header -->
    <view class="header">
      <view class="title">速算练习</view>
      <view class="subtitle">提升数学计算能力</view>
    </view>

    <!-- Main Functions -->
    <view class="functions">
      <!-- Speed Judge Function -->
      <view class="function-card" @tap="goToSpeedJudge">
        <view class="function-icon speed-judge-icon">
          <uni-icons color="#ffffff" size="40" type="link"></uni-icons>
        </view>
        <view class="function-info">
          <view class="function-title">速判练习</view>
          <view class="function-desc">分数与小数连线匹配</view>
          <view class="function-detail">1/20至1/2的分数转换练习</view>
        </view>
        <view class="function-arrow">
          <uni-icons color="#999" size="20" type="right"></uni-icons>
        </view>
      </view>

      <view class="function-card" @tap="goToSpeedJudgeChoice">
        <view class="function-icon speed-judge-icon">
          <uni-icons color="#ffffff" size="40" type="link"></uni-icons>
        </view>
        <view class="function-info">
          <view class="function-title">速判选择</view>
          <view class="function-desc">为分数选择正确的估算值</view>
          <view class="function-detail">1/20至1/2的分数转换练习</view>
        </view>
        <view class="function-arrow">
          <uni-icons color="#999" size="20" type="right"></uni-icons>
        </view>
      </view>

      <!-- Speed Calculation Function -->
      <view class="function-card" @tap="goToSpeedCalc">
        <view class="function-icon speed-calc-icon">
          <uni-icons color="#ffffff" size="40" type="compose"></uni-icons>
        </view>
        <view class="function-info">
          <view class="function-title">速算练习</view>
          <view class="function-desc">四则运算快速计算</view>
          <view class="function-detail">支持整数、小数、百分数</view>
        </view>
        <view class="function-arrow">
          <uni-icons color="#999" size="20" type="right"></uni-icons>
        </view>
      </view>

      <view class="function-card" @tap="goToSpeedCalcChoice">
        <view class="function-icon speed-calc-icon">
          <uni-icons color="#ffffff" size="40" type="compose"></uni-icons>
        </view>
        <view class="function-info">
          <view class="function-title">速算选择</view>
          <view class="function-desc">为四则运算选择正确的估算值</view>
          <view class="function-detail">支持整数、小数、百分数</view>
        </view>
        <view class="function-arrow">
          <uni-icons color="#999" size="20" type="right"></uni-icons>
        </view>
      </view>

      <view class="function-card" @tap="goToSpeedFormulaChoice">
        <view class="function-icon speed-formula-icon">
          <uni-icons color="#ffffff" size="40" type="paperclip"></uni-icons>
        </view>
        <view class="function-info">
          <view class="function-title">公式速判</view>
          <view class="function-desc">根据公式计算正确答案</view>
          <view class="function-detail">5种数据公式练习</view>
        </view>
        <view class="function-arrow">
          <uni-icons color="#999" size="20" type="right"></uni-icons>
        </view>
      </view>
    </view>

    <!-- Quick Stats -->
    <view v-if="recentStats" class="stats">
      <view class="stats-title">最近练习</view>
      <view class="stats-content">
        <view class="stat-item">
          <view class="stat-value">{{ recentStats.practiceCount }}</view>
          <view class="stat-label">练习次数</view>
        </view>
        <view class="stat-item">
          <view class="stat-value">{{ recentStats.accuracy }}%</view>
          <view class="stat-label">平均正确率</view>
        </view>
        <view class="stat-item">
          <view class="stat-value">{{ recentStats.bestScore }}</view>
          <view class="stat-label">最高分数</view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      recentStats: null
    }
  },
  onLoad() {
    this.loadRecentStats();
  },
  methods: {
    // Navigate to Speed Judge
    goToSpeedJudge() {
      uni.navigateTo({
        url: '/pages/speed-judge/settings'
      });
    },

    // Navigate to Speed Judge Choice
    goToSpeedJudgeChoice() {
      uni.navigateTo({
        url: '/pages/speed-judge-choice/settings'
      });
    },

    // Navigate to Speed Calculation
    goToSpeedCalc() {
      uni.navigateTo({
        url: '/pages/speed-calc/settings'
      });
    },

    // Navigate to Speed Calculation Choice
    goToSpeedCalcChoice() {
      uni.navigateTo({
        url: '/pages/speed-calc-choice/settings'
      });
    },

    // Navigate to Speed Formula Choice
    goToSpeedFormulaChoice() {
      uni.navigateTo({
        url: '/pages/speed-formula-choice/settings'
      });
    },

    // Load recent practice statistics
    loadRecentStats() {
      try {
        const stats = uni.getStorageSync('recent_stats');
        if (stats) {
          this.recentStats = stats;
        }
      } catch (e) {
        console.log('Failed to load recent stats:', e);
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.container {
  min-height: 100vh;
  background: linear-gradient(135deg, #a8f3f0 0%, #7dd3fc 100%);
  padding: 0;
}

.header {
  text-align: center;
  padding: 60rpx 40rpx 40rpx;
  color: white;

  .title {
    font-size: 48rpx;
    font-weight: bold;
    margin-bottom: 20rpx;
  }

  .subtitle {
    font-size: 28rpx;
    opacity: 0.9;
  }
}

.functions {
  padding: 0 40rpx;
  margin-bottom: 60rpx;
}

.function-card {
  background: white;
  border-radius: 20rpx;
  padding: 40rpx;
  margin-bottom: 30rpx;
  display: flex;
  align-items: center;
  box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.1);
  transition: transform 0.2s;

  &:active {
    transform: scale(0.98);
  }
}

.function-icon {
  width: 100rpx;
  height: 100rpx;
  border-radius: 20rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 30rpx;

  &.speed-judge-icon {
    background: linear-gradient(135deg, #ff6b6b, #ee5a52);
  }

  &.speed-calc-icon {
    background: linear-gradient(135deg, #67e8f9, #38bdf8);
  }

  &.speed-formula-icon {
    background: linear-gradient(135deg, #8a2be2, #9370db);
  }
}

.function-info {
  flex: 1;

  .function-title {
    font-size: 32rpx;
    font-weight: bold;
    color: #333;
    margin-bottom: 10rpx;
  }

  .function-desc {
    font-size: 28rpx;
    color: #666;
    margin-bottom: 8rpx;
  }

  .function-detail {
    font-size: 24rpx;
    color: #999;
  }
}

.function-arrow {
  margin-left: 20rpx;
}

.stats {
  background: white;
  margin: 0 40rpx;
  border-radius: 20rpx;
  padding: 40rpx;
  box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.1);

  .stats-title {
    font-size: 32rpx;
    font-weight: bold;
    color: #333;
    margin-bottom: 30rpx;
    text-align: center;
  }

  .stats-content {
    display: flex;
    justify-content: space-around;
  }

  .stat-item {
    text-align: center;

    .stat-value {
      font-size: 36rpx;
      font-weight: bold;
      color: #007AFF;
      margin-bottom: 10rpx;
    }

    .stat-label {
      font-size: 24rpx;
      color: #666;
    }
  }
}
</style>